var express = require('express');
const Result = require('../lib/Result');
const Manager = require('../db/models/manager/manager');
var router = express.Router();
/* 获取信息 */
router.post("/getInfo", function (req, res) {
    console.log(req.auth);
    Manager.getInfo(req.auth.username).then(value => {
        res.json(Result.success(value))
    })
})
//更改自己密码
router.post("/updatepassword", (req, res) => {
    let oldpassword = req.body.oldpassword;
    let password = req.body.password;
    let repassword = req.body.repassword
    console.log(req.body);
    Manager.getManagerByUserName(req.auth.username.username).then(value => {
        if (value[0].isPassword(oldpassword)) {
            if (password === repassword) {
                value[0].updatepassword(password).then(manager => {
                    if (manager != null) {
                        res.json(Result.success(true))
                    }
                })
            } else {
                res.json(Result.validateFailed())
            }
        } else {
            res.json(Result.validateFailed())
        }
    })
})

module.exports = router